// home模块
import { reqCategoryList, reqGetBannersList, reqGetFloorsList } from '@/api'
// 开启命名空间
const namespaced = true
// state：仓库储存数据
const state = {
  // 三级联动菜单
  categoryList: [],
  // 轮番图
  bannersList: [],
  // floor
  floorsList: []
}
// mutations：修改state唯一手段
const mutations = {
  CATEGORYLIST(state, categoryList) {
    state.categoryList = categoryList.slice(0, 15)
  },
  GETBANNERSLIST(state, bannersList) {
    state.bannersList = bannersList
  },
  GETFLOORSLIST(state, floorsList) {
    state.floorsList = floorsList
  }

}
// action：可以书写业务逻辑
const actions = {
  async categoryList({ commit }) {
    let result = await reqCategoryList()
    if (result.code === 200) {
      commit('CATEGORYLIST', result.data)
    }
  },
  async getBannersList({ commit }) {
    let result = await reqGetBannersList()
    if (result.code === 200) {
      commit('GETBANNERSLIST', result.data)
    }
  },
  async reqGetFloorsList({ commit }) {
    let result = await reqGetFloorsList()
    if (result.code === 200) {
      commit('GETFLOORSLIST', result.data)
    }
  },
  
}
// getters：理解为计算属性，用于简化仓库数据
const getters = {}

export default {
  namespaced,
  state,
  mutations,
  actions,
  getters
}